<template>
    <a-card :bordered="false">
        
        <div class="table-operator">
            <a-button shape="round" size="small" type="primary" icon="plus" @click="add" :loading="loading">添加</a-button>
            <a-button shape="round" size="small" type="primary" icon="delete" @click="del">删除</a-button>
            <a-button shape="round" size="small" type="primary" icon="save" @click="save">保存</a-button>
            <!-- <a-button shape="round" size="small" type="primary" icon="cloud-upload" @click="excelUpload">导入数据</a-button>
            <a-button shape="round" size="small" type="primary" icon="cloud-download" @click="excelDownload">导出数据</a-button> -->
        </div>

        <LTable
            ref="empListTable"
            size="small"
            rowKey="keyId"
            :formAttributes="formAttributes"
            :columns="columns"
            axiosUrl="/SysEmpController/page"
            :showPagination="true"
            :showQueryForm="true"
            :initDictCodes="initDictCodes"
            :rowSelection="{onChange: onSelectChange }">
            <template  v-for="(column,i) in columns" :slot="column.dataIndex" slot-scope="text, record, index" >
                <LEditTableColumn :key="i" rowKey="keyId" :initDictCodes="initDictCodes" :record="record" :column="column" :index="index" :text="text" :table="$refs['empListTable']"></LEditTableColumn>
            </template>
            <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record,'empForm',record.empName)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete({keyId:record.keyId,accountNo:record.accountNo},'/SysEmpController/del','empListTable')">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-if="record.isUse==1">
                  <a-popconfirm title="确定冻结吗?" @confirm="() => handlefreeze({keyId:record.keyId})">
                  <a>冻结</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item v-else>
                <a-popconfirm title="确定解冻吗?" @confirm="() => handleUnfreeze({keyId:record.keyId})">
                  <a>解冻</a>
                </a-popconfirm>
              </a-menu-item>
              <a-menu-item>
                  <a-popconfirm title="确定密码重置吗?" @confirm="() => handleResetPwd({keyId:record.keyId})">
                  <a>密码重置</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
        
        </LTable>
        <empForm ref="empForm" @close="refresh('empListTable')" @ok="refresh('empListTable')"></empForm> 
        <LExcelUpload ref="LExcelUpload" templateId="1714549154263592961" templateName="人员信息导入模板"></LExcelUpload>
        <LExcelDownload ref="LExcelDownload" templateId="1714549154263592961" templateName="人员信息"></LExcelDownload>
    </a-card>
</template>

<script>
import LTable from '@/components/lt/LTable'
import request from '@/utils/request'
import empForm from './empForm'
import {SysMixin} from '@/mixins/SysMixin'
import LExcelUpload from '@/components/lt/LExcelUpload'
import LExcelDownload from '@/components/lt/LExcelDownload'
import defaultSettings from '@/config/defaultSettings'
import LEditTableColumn from '@/components/lt/editTable/LEditTableColumn'

export default {
    name:'empEditList',
    components:{
       LTable,empForm,LExcelUpload,LExcelDownload,LEditTableColumn
    },
    mixins:[SysMixin],
    data(){
        return{
            initDictCodes:defaultSettings.数据字典.组织下拉树+','+defaultSettings.数据字典.是否,
            defaultSettings,
            formAttributes:[
                
                {field:'empName',label:'人员姓名',component:'input',condition:'like'},
                {field:'accountNo',label:'账号',component:'input',condition:'like'},
            ],
            loading:false,
            //regExp:/^1[3,4,5,6,7,8,9][0-9]\d{8}$/
            columns:[
                {
                    title: '序号',
                    dataIndex: '',
                    key:'rowIndex',
                    width:60,
                    align:"center",
                    customRender:function (t,r,index) {
                      return parseInt(index)+1;
                    }
                },
                 {
                    title: '组织',
                    dataIndex: 'orgNo',
                    scopedSlots: { customRender: 'orgNo' },
                    width:'200px',
                    editable:false,component:'treeSelect',required:true,dictCode:defaultSettings.数据字典.组织下拉树,multiple:false,
                    // customRender:(text)=>{
                    //     if(!text){
                    //         return ''
                    //     }else{
                    //         return this.dictText(defaultSettings.数据字典.组织下拉树,text)
                    //     }
                    // }
                },
                
                {
                    title: '人员编号',
                    dataIndex: 'empNo',
                    scopedSlots: { customRender: 'empNo' },
                    editable:true,component:'input',required:true,
                },
                {
                    title: '人员姓名',
                    dataIndex: 'empName',
                    scopedSlots: { customRender: 'empName' },
                    editable:true,component:'input',required:true,
                },
                {
                    title: '登陆账号',
                    dataIndex: 'accountNo',
                    scopedSlots: { customRender: 'accountNo' },
                    editable:true,component:'input',required:true,
                    
                },
                {
                    title: '状态',
                    dataIndex: 'isUse',
                    scopedSlots: { customRender: 'isUse' },
                    editable:true,component:'select',required:true,dictCode:defaultSettings.数据字典.是否,
                    width:'200px'
                },
                {
                    title: '创建时间',
                    dataIndex: 'createTime',
                    scopedSlots: { customRender: 'createTime' },
                    editable:true,component:'time',required:true,
                    width:'200px'
                },
                {
                    title: '操作',
                    dataIndex: 'action',
                    width: '120px',
                    scopedSlots: { customRender: 'action' }
                }
            ],
            
        }
    },
    created(){
       
    },
    mounted(){
       
    },
    methods:{
        onSelectChange (selectedRowKeys, selectedRows) {},
        add(){
            this.loading=true
            this.$refs['empListTable'].batchAdd()
            setTimeout(() => {
                this.loading=false
            }, 200);
            
        },
        save(){
            this.$refs['empListTable'].batchSave()
        },
        del(){
            this.$refs['empListTable'].batchDel()
        },
        handlefreeze(params){
            var that = this;
            request.get('/SysEmpController/freeze',{params:params}).then((res)=>{
                if (res.success) {
                    that.$message.success(res.message);
                    that.refresh('empListTable');
                } else {
                    that.$message.warning(res.message);
                }
            })
        },
        handleUnfreeze(params){
            var that = this;
            request.get('/SysEmpController/unfreeze',{params:params}).then((res)=>{
                if (res.success) {
                    that.$message.success(res.message);
                    that.refresh('empListTable');
                } else {
                    that.$message.warning(res.message);
                }
            })
        },
        handleResetPwd(params){
            var that = this;
            request.get('/SysEmpController/resetPwd',{params:params}).then((res)=>{
                if (res.success) {
                    that.$message.success(res.message);
                    that.refresh('empListTable');
                } else {
                    that.$message.warning(res.message);
                }
            })
        },
        excelUpload(){
            this.$refs['LExcelUpload'].show();
        },
        excelDownload(){
            this.$refs['LExcelDownload'].show();
        }
    }
}
</script>

<style lang="less" scoped>
    // ::v-deep .ant-table-small > .ant-table-content > .ant-table-body > table > .ant-table-tbody > tr > td{
    //     padding: 2px 8px;
     
    // }
    // ::v-deep .ant-input-sm{
    //     height: 30px;
    // }
    
</style>